<template>
	<div class="header">
		<div>
			<img src="@/assets/images/wechat/index/public/logo.jpg">
		</div>
	</div>
	
	<div class="info">
		<form>
			<div class="info_common">
				<label><img src="@/assets/images/wechat/index/lawyerlogin/findpassword_number.png"></label>
				<input type="text" v-model="lawyerData.acctno" placeholder="请输入账号" maxlength="20">
			</div>
			<div class="info_common">
				<label><img src="@/assets/images/wechat/index/lawyerlogin/login_passwd.png"></label>
				<input type="password" v-model="lawyerData.passwd" placeholder="请输入密码" maxlength="22">
			</div>
			<input @click="findLawyer" type="button" value="登录">
			<a @click="wechatAuth()">微信一键登录</a>
		</form>
		
	</div>
	<div class="footer">
		<p>版权所有：重庆木舌科技有限公司</p>
		<p>技术支持：重庆欣儿科技有限公司</p>
		<p>Copyright © 2018-2021 www.lawguanjia.com</p>
	</div>
</template>

<script>
//引入js
import router from '@/router/index'
import { loginByAcctno } from '@/api/lawyer'
import jsMd5 from 'js-md5'
	
export default {
  components: {
  },
  data(){
    return {
		baseUrl:process.env.VUE_APP_BASE_API,
		appId:"",
		
		lawyerData:{
			acctno:"",
			passwd:""
		}
    }
  },
  created:function(){
	this.appId=this.$store.state.globalData.wechatConfig.appId
  },
  beforeMount: function() {
	  
  },
  mounted: function () {
	  
  },
  methods:{
	findLawyer:async function(){
		if(!this.lawyerData.acctno)
		{
			alert("请填写账号")
			return
		}
		if(!this.lawyerData.passwd)
		{
			alert("请填写密码")
			return
		}
		var ajaxData={}
		ajaxData.acctno=this.lawyerData.acctno;
		ajaxData.passwd=jsMd5(this.lawyerData.passwd);
		var resultData=await loginByAcctno(ajaxData)
		if(resultData.code==200)
		{
			//存起来token和身份信息
			var expireTime=Date.parse(new Date())/1000+72000;//20小时后过期
			//同步更新store
			this.$store.commit("setIdentity",6);
			this.$store.commit("setToken",resultData.data);
			this.$store.commit("setExpireTime",expireTime);
			 /*存储到ls*/
			localStorage.setItem('identity',6);
			localStorage.setItem('token',resultData.data);
			localStorage.setItem('expireTime',expireTime);
			
			router.replace({path:"/wechatlawyer/lawyercenter"});
			return;
		}else{
			alert("登录失败")
		}
	},
	wechatAuth:function(){
		var that=this;
		window.location="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+this.appId+"&redirect_uri="+encodeURIComponent("https://www.lawguanjia.com/#/wechat/lawyerauthlogin")+"&response_type=code&scope=snsapi_userinfo#wechat_redirect";
	}
  }
}
</script>

<style lang="scss" scoped>
.header{ width:100%; overflow:hidden;}
.header>div{ width:80px; height:80px; margin:auto; margin-top:40px; margin-bottom:40px; overflow:hidden;}
.header>div>img{ width:100%;}

.info{ width:100%; overflow:hidden}
.info>form{ width:300px; margin:auto;}
.info_common{ width:100%; height:42px; overflow:hidden;border-bottom:1px solid #E8E8E8; margin-top:10px; position:relative}
.info_common>label{ width:36px; height:36px; float:left; overflow:hidden; }
.info_common>label>img{ width:20px; height:20px; margin-top:8px; margin-left:8px;}
.info_common>input{ width:264px; float:left; height:36px; border:none; outline:none; text-indent:10px; font-size:14px;}
.info_common_verify{ width:120px;height:36px; position:absolute; right:0; top:0;}
.info>form>input[type="button"]{ width:300px;height:42px;border:1px solid #0054bc; margin-top:24px; color:#FFF; background:#0054bc; outline:none; border-radius:4px; font-size:14px;}
.info>form>a{ width:298px;line-height:40px;display:block;border:1px solid #0054bc; margin-top:12px; color:#FFF; background:#0054bc; border-radius:4px; font-size:14px; text-align: center;}

.footer{ width:100%; max-width:400px; margin:auto; margin-top:20px;}
.footer>p{ text-align: center;font-size: 12px;color: #999; line-height: 24px; }
</style>
